package io.renren;

import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;
import org.junit.Test;

import java.io.*;

public class Demo {

    @Test
    public void TestParse() throws FileNotFoundException {
        String url = "D:\\java\\workspace\\mailattachment\\简历.doc";
        File file = new File(url);
        try {
            Demo demo = new Demo();
            String s = demo.readText(file);
            System.out.println(s);
        } catch (Exception e) {
            e.printStackTrace();
        }


    }



    public String readText(File file ) throws Exception {
        String text = "";
        BufferedInputStream fis2 = null;
        try {

            fis2 = new BufferedInputStream(new FileInputStream(file), 2048);
            HWPFDocument document = new HWPFDocument(fis2);
            WordExtractor extractor = new WordExtractor(document);
            text = extractor.getText();

        } finally {
            if (fis2 != null) {
                try {
                    fis2.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        }
        return text;
    }


    public  String readInput(InputStream input) throws Exception {
        String text = "";
        BufferedInputStream fis2 = null;
        try {

            fis2 = new BufferedInputStream(input, 2048);
            HWPFDocument document = new HWPFDocument(fis2);
            WordExtractor extractor = new WordExtractor(document);
            text = extractor.getText();

        } finally {
            if (fis2 != null) {
                try {
                    fis2.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        }
        return text;
    }
}
